f = Sin() ∘ (1 / Polynomial(0, 1, d=0.0 .. 0.05))
fplot(f, yscale=0.05, npoints=11)4 Mathematics
4.1 Mappings
4.1.1 Functions \(\mathbb{R} \to \mathbb{R}\)
s = Sin(0 .. 3π)
c = Cos(0 .. 3π)
f = 2s
g = s + f'
p = 1 / 20 * Polynomial([2, -1], 1 .. 8) * Polynomial([3, -1]) * Polynomial([4.5, -1]) * Polynomial([8, -1])
fplot(c, s, g, p)f = Polynomial([0, 1], -1 .. 1)
F = antiderivative(f)
fplot(f, F)integrate(f, 0 .. 1)0.5
p = [0, 1, 2]
f = fplot(fromroots(p, -0.1 .. 2.1))
scatter!(p, 0 * p, color=:tomato)
fp = [0, 1.5, 2]
f = fplot(lagrangepolynomials(p, 0 .. 2)...)
scatter!(p, [0, 0, 0], color=:tomato)
scatter!(p, [1, 1, 1], color=:blue)
f4.1.2 Parametric curves
Lissajous curve
u = ParametricCurve(Cos(0 .. 2π), Sin() ∘ Polynomial(0, 2, d=0 .. 2pi))
v = 0.075 * Sin() ∘ Polynomial(0, 100) * UnitNormal(u)
w = 0.025 * ParametricCurve(Sin(), Cos()) ∘ Polynomial(0, 200)
fplot(u, u + v, u + w)Interpolate points
points = tomatrix([[0.0, 0], [1.5, 1], [2, 0], [1.5, -1], [0, 0]])
L = lagrangepolynomials(range(IHat, size(points, 2)), IHat)
u = Interpolation(L, points)
fig, ax = fplot(u)
scatter!(ax, points, color=:tomato)
fig4.1.3 Monomials
fplot(monomials(0:100, 0 .. 1)...)4.1.4 Functions of two variables
Create the function \(f : [0, 5\pi]^2 \to \mathbb{R}, \quad f(\mathbf{x}) = \sin x_1 \sin x_2\)
f = makefunction(x -> exp(-hypot(x[1], x[2])^2 / 20) * cos(x[1]) * cos(x[2]), -2π .. 2π, -2π .. 2π);By default the plot is a view down from positive \(z\) direction
fplot3d(f, mesh=9)Create a 3D plot using Axis3 and switch of the mesh off since CairoMakie does not handle hidden lines.
fig = Figure()
Axis3(fig[1, 1])
fplot3d!(f, npoints=250, mesh=nothing)
figA (sometimes?) interactive 3D plot is obtained using WebGL:
GLMakie.activate!()
fig = Figure()
Axis3(fig[1, 1])
fplot3d!(f, mesh=19, npoints=250)
figMultivariate polynomial \(f(x, y) = x^2 y - y\)
g = MPolynomial([2 1; 0 1], [1.0, -1.0], QHat)
fig = Figure()
Axis3(fig[1, 1])
fplot3d!(g)
figMultivariate monomials
fplot3d(mmonomials(2, 3, QHat))Plot gradient of product function
CairoMakie.activate!()
g = ProductFunction(Sin(0 .. 2π), Sin(0 .. 2π))
fig = Figure()
Axis(fig[1, 1])
fplot3d!(g, mesh=nothing)
vplot!(gradient(g), npoints=9, lengthscale=0.3)
fig